package cn.tsinghua.comsmacitccntsinghua.model;

import android.app.Activity;
import android.content.Context;
import android.widget.ImageView;
import android.widget.Toast;
import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;
import cn.bingoogolapple.bgabanner.BGABanner;
import cn.tsinghua.comsmacitccntsinghua.R;
import cn.tsinghua.comsmacitccntsinghua.bean.BaseDataInfo;

/**
 * 顶部轮播图控制类
 */
public class BannerControl {
    private Context mContext;
    private BGABanner banner;
    public BannerControl(Context context, BGABanner bgaBanner) {
        this.mContext = context;
        this.banner = bgaBanner;
        setAdapter(context);
    }

    //设置轮播图适配器
    public void setAdapter(final Context context){
        banner.setAdapter(new BGABanner.Adapter<ImageView, String>() {
            @Override
            public void fillBannerItem(BGABanner banner, ImageView itemView, String model, int position) {
                Glide.with(context)
                        .load(model)
                        .placeholder(R.drawable.holder)
                        .error(R.drawable.holder)
                        .centerCrop()
                        .dontAnimate()
                        .into(itemView);
            }
        });
    }
    //设置轮播图数据
    //public void setData(List arUrl,List arTip){
    public void setData(List<BaseDataInfo.DataBean.BannerBean> bannerBeanList){
        List urlList = new ArrayList();
        List tipList = new ArrayList();
        for (int k=0;k<bannerBeanList.size();k++){
            urlList.add(bannerBeanList.get(k).getBannerUrl());
           // tipList.add(bannerBeanList.get(k).getBannerDes());
        }
        banner.setData(urlList,tipList);
    }
    //轮播图点击事件处理
    public void onClickListener(){
        banner.setDelegate(new BGABanner.Delegate<ImageView, String>() {
            @Override
            public void onBannerItemClick(BGABanner banner, ImageView itemView, String model, int position) {
                //TODO 点击事件处理
            }
        });
    }
}
